<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <div id="app">
      <h1>构造器的生命周期</h1>
      <span>分数:{{point}}</span><br />
      <button v-on:click="add">绑定加分</button>
      <button v-on:click="unbind">解绑</button>
    </div>

    <script>
      var app = new Vue({
        el: "#app",
        data: {
          point: 0,
        },
        methods: {
          add: function () {
            ++this.point;
          },
          unbind: function () {
            app.$destroy();
          },
        },
        beforeCreate: function () {
          console.log("1-beforeCreate 初始化之后");
        },
        created: function () {
          console.log("2-created 创建完成");
        },
        beforeMount: function () {
          console.log("3-beforeMount 挂载之前");
        },
        mounted: function () {
          console.log("4-mounted 被创建");
        },
        beforeUpdate: function () {
          console.log("5-beforeUpdate 数据更新前");
        },
        updated: function () {
          console.log("6-updated 被更新后");
        },
        activated: function () {
          console.log("7-activated");
        },
        deactivated: function () {
          console.log("8-deactivated");
        },
        beforeDestroy: function () {
          console.log("9-beforeDestroy 销毁之前");
        },
        destroyed: function () {
          console.log("10-destroyed 销毁之后");
        },
      });
    </script>
  </body>
</html>
